package com.two.screen.water.balance.print.android_print.usb

import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.hardware.usb.UsbDevice
import android.hardware.usb.UsbInterface
import android.hardware.usb.UsbManager
import com.android.print.sdk.PrinterConstants
import com.two.screen.water.balance.net.api.DataApi
import com.two.screen.water.balance.print.all.Table
import com.two.screen.water.balance.print.all.USBPrinterAll
import com.two.screen.water.balance.print.all.UsbPrinter
import com.two.screen.water.balance.print.all.ZXingUtils
import com.two.screen.water.balance.print.bean.PrintConnectBean
import com.two.screen.water.balance.print.bean.PrintConnectSaleReportBean
import com.two.screen.water.balance.print.bean.PrintOrderBean
import com.two.screen.water.balance.print.bean.PrintServerCollectOrderBean
import com.two.screen.water.balance.ui.App
import com.two.screen.water.balance.utils.CommUtils
import com.two.screen.water.balance.utils.Params
import com.two.screen.water.balance.utils.SPUtils
import com.two.screen.water.balance.utils.eventbus.Event
import com.two.screen.water.balance.utils.eventbus.EventBusUtil
import com.two.screen.water.balance.utils.eventbus.EventCode
import com.two.screen.water.balance.utils.isNotAvailable

@SuppressLint("StaticFieldLeak")
object AndroidUSBPrinter {
    private var mPermissionIntent: PendingIntent? = null
    private var mUsbManager: UsbManager? = null
    private var usbInterface: UsbInterface? = null

    var myOpertion: UsbOperation? = null
    var mIsOpenSuccess = false

    fun initUsbDevice() {
        try {
            mUsbManager = App.context!!.getSystemService(Context.USB_SERVICE) as UsbManager
            if (mUsbManager == null) return
            mPermissionIntent = PendingIntent.getBroadcast(App.context!!, 0, Intent(UsbPrinter.ACTION_USB_PERMISSION), 0)
            // 注册广播监听usb设备
            val filter = IntentFilter(UsbPrinter.ACTION_USB_PERMISSION)
            filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED)
            filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED)
            App.context!!.registerReceiver(mUsbDeviceReceiver, filter)
            // 列出所有的USB设备，并且都请求获取USB权限
            val deviceList = mUsbManager?.deviceList ?: return
            for (device in deviceList.values) {
                // 得到此设备的一个接口
                usbInterface = device.getInterface(0)
                // 获取接口的类别 7代表连接的是打印机
                // 获取接口的类别 7代表连接的是打印机
                d("UsbDevice->getInterfaceCount:" + device.interfaceCount)
                d("UsbDevice->getDeviceName:" + device.deviceName)
                d("UsbDevice->getProductName:" + device.productName)
                d("UsbDevice->getDeviceId:" + device.deviceId)
                d("UsbDevice->getProductId:" + device.productId)
                d("UsbDevice->getVendorId:" + device.vendorId)
                d("usbInterface->getVendorId:" + usbInterface!!.name)
                d("usbInterface->getVendorId:" + usbInterface!!.interfaceClass)
                if (usbInterface?.interfaceClass == 7) {
                    // 1137     85      1027
                    // 26728     1280      1045+2
                    if (!mUsbManager!!.hasPermission(device)) {
                        d("正在连接此设备...但没权限，正在请求")
                        mUsbManager!!.requestPermission(device, mPermissionIntent)
                    } else {
                        d("正在连接此设备...")
                        connectUsbPrinter(device)
                    }
                }
                d("-------------------------------------------------")
            }
        } catch (e: Exception) {
            d("open failed:$e")
        }
    }

    private val mUsbDeviceReceiver: BroadcastReceiver = object : BroadcastReceiver() {
        override fun onReceive(context: Context, intent: Intent) {
            val action = intent.action
            val mUsbDevice = intent.getParcelableExtra<UsbDevice>(UsbManager.EXTRA_DEVICE)
            d("广播监听到有设备动静：getProductName:" + mUsbDevice!!.productName)
            if (UsbPrinter.ACTION_USB_PERMISSION == action) {
                synchronized(this) {
                    if (intent.getBooleanExtra(UsbManager.EXTRA_PERMISSION_GRANTED, false) && mUsbDevice != null) {
                        d("拿到权限了，正在连接此设备")
                        connectUsbPrinter(mUsbDevice)
                    } else {
                        d("USB设备请求被拒绝")
                    }
                }
            } else if (UsbManager.ACTION_USB_DEVICE_DETACHED == action) {
                if (mUsbDevice != null) {
                    d("有设备拔出")
                }
            } else if (UsbManager.ACTION_USB_DEVICE_ATTACHED == action) {
                d("有设备插入")
                if (mUsbDevice != null) {
                    if (!mUsbManager!!.hasPermission(mUsbDevice)) {
                        d("但没有权限，重新申请...")
                        mUsbManager!!.requestPermission(mUsbDevice, mPermissionIntent)
                    } else {
                        d("有权限，去连接打印")
                        connectUsbPrinter(mUsbDevice)
                    }
                }
            }
        }
    }

    private fun connectUsbPrinter(device: UsbDevice?) {
        d("开始保存：vendorId:${device?.vendorId},productId:${device?.productId},")
        DataApi.mUSBDevicePath = "PID:${device?.productId},VID:${device?.vendorId},NAME:${device?.productName}"
        SPUtils.putString(Params.mUSBDevicePath, DataApi.mUSBDevicePath)
        EventBusUtil.sendEvent(Event(EventCode.ANDROID_USB_PRINT_OPEN, device))
    }

    fun printTest() {
        var times = DataApi.mBillPrintTimesArray[DataApi.mBillPrintTimesIndex].toInt()
        myOpertion?.printer?.init()
        for (time in 1..times) {
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.setFont(0, 0, 1, 0);//加粗
            myOpertion?.printer?.printText("测试打印")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.setFont(0, 0, 0, 0);//取消加粗
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左
            myOpertion?.printer?.printText("一二三四五六七八九十")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("==============================================")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);// 换行
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.printImage(ZXingUtils.createQRCodeBitmap("测试打印二维码", 200))//二维码
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);// 换行
            myOpertion?.printer?.printText("12345678910..")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);// 换行
        }
    }

    fun printOrder(data: PrintOrderBean?) {
        var times = DataApi.mBillPrintTimesArray[DataApi.mBillPrintTimesIndex].toInt()
        for (time in 1..times) {
            USBPrinterAll.usbPrinter?.init()
            myOpertion?.printer?.setFont(1, 1, 0, 0);//加粗+放大一倍
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.printText(data?.title)
            myOpertion?.printer?.setFont(0, 0, 0, 0);//正常大小
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);// 换行

            myOpertion?.printer?.printText("市场名称：${DataApi.mMarketName.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("商户名称：${DataApi.mShopName.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("档口号：${DataApi.mShopStallName.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("订单编号：${data?.orderSn.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("收银时间：${data?.collectionTime.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("操作人：${data?.operationName.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText(data?.orderPriceInfo.isNotAvailable())
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("支付信息：${data?.payInfo.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行


            if (data?.productList != null && data.productList!!.isNotEmpty()) {
                myOpertion?.printer?.printText("-------------------------------")
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
                myOpertion?.printer?.printText("品名")
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
                val tableHead = "数量;单价;金额"
                var table: Table? = Table(tableHead, ";", intArrayOf(14, 10, 14))
                table?.addRow("-------------------------------")
                data.productList?.indices?.forEach {
                    var bean = data.productList!![it]
                    table?.addRow(bean.name ?: "商品")
                    table?.addRow("${bean.weight ?: "0.000"};${bean.price ?: "0.00"};${bean.subPrice ?: "0.00"}")
                }
                myOpertion?.printer?.printText(table?.tableText)
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
                myOpertion?.printer?.printText("-------------------------------")
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            }
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左
            myOpertion?.printer?.printText(data?.orderTotal.isNotAvailable())
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.setFont(0, 0, 1, 0);//加粗
            if (data?.qrCode != null && data.qrCode!!.isNotBlank()) {
                myOpertion?.printer?.printText(data.qrCodeTipsTop.isNotAvailable())
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);// 换行
                myOpertion?.printer?.printImage(ZXingUtils.createQRCodeBitmap(data.qrCode, 200))//二维码
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 3);// 换行
            }
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.printText(data?.qrCodeTipsBottom.isNotAvailable())
            myOpertion?.printer?.setFont(0, 0, 0, 0);//正常大小
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 5);// 换行
        }
    }

    fun printConnectStatics(data: PrintConnectBean?) {
        USBPrinterAll.usbPrinter?.init()
        var times = DataApi.mBillPrintTimesArray[DataApi.mBillPrintTimesIndex].toInt()
        for (time in 1..times) {
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.setFont(1, 1, 0, 0);//加粗
            myOpertion?.printer?.printText(data?.title)
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);// 换行
            myOpertion?.printer?.setFont(0, 0, 0, 0);//取消加粗
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左

            myOpertion?.printer?.printText("收银员：${data?.operationName.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("起始时间：${data?.startTime.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("结束时间：${data?.endTime.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("-------------------------------")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

            myOpertion?.printer?.printText("总单数：　　　　${data?.billTotal.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("门店：　　　　　${data?.billShop.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("退货：　　　　　${data?.billReturn.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("反结账：　　　　${data?.billReverse.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("-------------------------------")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

            myOpertion?.printer?.printText("总实收金额：　　${data?.realTotalPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("现金实收：　　　${data?.realCashPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("微会员实收：　　${data?.realWetchVipPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("聚合支付实收：　${data?.realJuHePrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("扫码收款实收：　${data?.realScanQrPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("-------------------------------")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

            myOpertion?.printer?.printText("总销售额：　　　${data?.saleTotalPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("现金：　　　　　${data?.saleCashPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("微会员：　　　　${data?.saleWetchVipPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("聚合支付：　　　${data?.saleJuHePrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("扫码收款：　　　${data?.saleScanQrPrice.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("-------------------------------")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 7);// 换行
        }
    }

    fun printConnectSaleReport(data: PrintConnectSaleReportBean?) {
        USBPrinterAll.usbPrinter?.init()
        var times = DataApi.mBillPrintTimesArray[DataApi.mBillPrintTimesIndex].toInt()
        for (time in 1..times) {
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.setFont(1, 1, 0, 0);//加粗
            myOpertion?.printer?.printText(data?.title)
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);// 换行
            myOpertion?.printer?.setFont(0, 0, 0, 0);//取消加粗
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左

            myOpertion?.printer?.printText("收银员：${data?.operationName.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("统计时间：${CommUtils.toYMD_HMS(System.currentTimeMillis() / 1000)}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("起始 ${data?.startTime.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("结束 ${data?.endTime.isNotAvailable()}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行


            if (data?.productList != null && data.productList!!.isNotEmpty()) {
                myOpertion?.printer?.printText("-------------------------------")
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
                myOpertion?.printer?.printText("品名")
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

                val tableHead = "数量;单价;小计"
                var table: Table? = Table(tableHead, ";", intArrayOf(14, 10, 14))
                table?.addRow("-------------------------------")
                data.productList?.indices?.forEach {
                    var bean = data.productList!![it]
                    table?.addRow(bean.name ?: "商品")
                    table?.addRow("${bean.weight ?: "0.000"};${bean.price ?: "0.00"};${bean.subPrice ?: "0.00"}")
                }
                myOpertion?.printer?.printText(table?.tableText)
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
                myOpertion?.printer?.printText("-------------------------------")
                myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            }
            myOpertion?.printer?.printText(data?.total.isNotAvailable())
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 7);// 换行
        }
    }

    fun closePrinter() {
        mIsOpenSuccess = false
        try {
            mUsbManager = null
            myOpertion?.close()
            myOpertion = null
            mUsbDeviceReceiver.let { App.context!!.unregisterReceiver(it) }
        } catch (e: Exception) {
            d("closePrinter:$e")
        }
    }

    private fun d(msg: String) {
        CommUtils.println("AndroidUSBPrinter->", msg)
    }

    fun printServerCollectOrder(printBean: PrintServerCollectOrderBean) {
        USBPrinterAll.usbPrinter?.init()
        var times = DataApi.mBillPrintTimesArray[DataApi.mBillPrintTimesIndex].toInt()
        for (time in 1..times) {
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 1);//居中
            myOpertion?.printer?.setFont(1, 1, 0, 0);//加粗
            myOpertion?.printer?.printText(printBean.title)
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 2);// 换行
            myOpertion?.printer?.setFont(0, 0, 0, 0);//取消加粗
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.ALIGN, 0);//居左

            myOpertion?.printer?.printText("${printBean.shopName}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.startTime}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.endTime}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("-------------------------------")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

            myOpertion?.printer?.printText("${printBean.totalPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.findZeroPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.giftPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.realPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.orderNumbers}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("-------------------------------")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

            myOpertion?.printer?.printText("${printBean.cashPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.miniProgramPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.vipPirce}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.juhePrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行
            myOpertion?.printer?.printText("${printBean.scanQrPrice}")
            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 1);// 换行

            myOpertion?.printer?.setPrinter(PrinterConstants.Command.PRINT_AND_WAKE_PAPER_BY_LINE, 7);// 换行
        }
    }
}